import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.*;


public class Record implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static 
	 List<String[]> completed=new ArrayList<String[]>(),
	 downloading=new ArrayList<String[]>();
	 List<Downloader> downloaders = new ArrayList<Downloader> ();  
	 static void addCompleted(String[] ss){
		 completed.add(ss);
		 serialize();
	 }
	 static void addDownloading(String[] ss){
		 downloading.add(ss);
		 serialize();
	 }
	 static void delCompleted(Object index){
		 completed.remove(index);
		 serialize();
	 }
	 static void delDownloading(Object index){
		 downloading.remove(index);
		 completed.add((String[])index);
		 serialize();
	 }
	 static void delCompleted(int index){
		 completed.remove(index);
		 serialize();
	 }
	 static void delDownloading(int index){
		 downloading.remove(index);
		 serialize();
	 }
	 static boolean hasCompleted(String []a){
		 return completed.contains(a);
	 }
	 static boolean hasDownloading(String []a){
		return downloading.contains(a);
	 }
	 
	 static void serialize(){
		 try {
			 ObjectOutputStream outputStream= new ObjectOutputStream(new FileOutputStream("Record"));
			 outputStream.writeObject(new Object[]{downloading,completed});
		 }	catch (Exception e) {
			 // TODO Auto-generated catch block
			 e.printStackTrace();
		 }
	 }
	static void deSerialize(DLFrame comp){
		 try {
			ObjectInputStream inputStream= new ObjectInputStream(new FileInputStream("Record"));
			Object readObject = inputStream.readObject();
			if(readObject !=null){
				Object[] os=(Object[])readObject;
				downloading=(List<String[]>)os[0];
				completed=(List<String[]>)os[1];
				for (String[] object : downloading) {
					DLFrame.addtask(object, comp,false);
				}
				comp.completedTableModel.model=completed;
				comp.dataModel.fireTableDataChanged();
				comp.completedTableModel.fireTableDataChanged();
			}
		 }	catch (Exception e) {
			
		}
	 }

}
